import request from '@/utils/request'

// 获取文章详情
const getArticleDetailAPI = ({ articleId }) => {
  return request({
    method: 'get',
    // url: '/v1_0/articles/' + articleId,
    url: `/v1_0/articles/${articleId}`
  })
}

// 关注作者
const followAutAPI = ({ authorId }) => {
  return request({
    method: 'post',
    url: '/v1_0/user/followings',
    data: {
      target: authorId
    }
  })
}
// 取关作者
const unfollowAutAPI = ({ authorId }) => {
  return request({
    method: 'delete',
    url: `/v1_0/user/followings/${authorId}`
  })
}

// 文章 - 点赞
const likeArticleAPI = ({ articleId }) => {
  return request({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: articleId
    }
  })
}
// 文章 - 取赞
const dislikeArticleAPI = ({ articleId }) => {
  return request({
    method: 'delete',
    url: `/v1_0/article/likings/${articleId}`
  })
}

// 文章 - 获取评论
const getArticleCommentAPI = ({ articleId, offset, limit = 10 }) => {
  return request({
    method: 'get',
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: articleId,
      offset,
      limit
    }
  })
}

// 评论 - 喜欢
const likeCommentAPI = ({ commentId }) => {
  return request({
    method: 'post',
    url: '/v1_0/comment/likings',
    data: {
      target: commentId
    }
  })
}
// 评论 - 不喜欢
const dislikeCommentAPI = ({ commentId }) => {
  return request({
    method: 'delete',
    url: `/v1_0/comment/likings/${commentId}`
  })
}

// 评论 - 发布
const publishCommentAPI = ({ articleId, content }) => {
  return request({
    method: 'post',
    url: '/v1_0/comments',
    data: {
      target: articleId,
      content
    }
  })
}

export {
  getArticleDetailAPI,
  followAutAPI,
  unfollowAutAPI,
  likeArticleAPI,
  dislikeArticleAPI,
  getArticleCommentAPI,
  likeCommentAPI,
  dislikeCommentAPI,
  publishCommentAPI
}
